package shooter.maps;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

import shooter.Einstellungen;

/**
 * This frame appears if the user wanted to start the map editor.
 * Now he could chose which size the editor should have.
 * Afterwards it starts the editor.
 * 
 * @author Michail Tausch
 */
public class Mapquestion extends javax.swing.JFrame {
	
	private AudioClip buttonSound;

	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor of this class. Creates the frame.
	 */
    public Mapquestion() {        
        this.getContentPane().setPreferredSize(new Dimension(400,170));
        this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(Einstellungen.getShooterImageFolderPath()+"CF.png")));
    	this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    	this.setName("Frage");
    	this.setVisible(true);
    	this.setLocationRelativeTo(null);
    	this.setResizable(false);
    	this.setLayout(null);
    	this.pack();
    	
    	try {
    		buttonSound = Applet.newAudioClip(new URL(getClass().getResource(Einstellungen.getSoundsWeaponsFolderPath()+"6.wav").toString()));
		} 
		catch (MalformedURLException e) {
			System.out.println("Audiofile Error: Malformed URI (file not found)");
		}
		
    	initComponents();
    }

    /**
     * Initializes the frame with all components. 
     */
    private void initComponents() {
    	
    	this.getContentPane().setBackground(Color.WHITE);
    	
    	final JLabel frage = new JLabel(new ImageIcon(getClass().getResource(Einstellungen.getMenuImageFolderPath()+"mapquestion.png")));
	    frage.setBounds(25, 10, 350, 50);
	    
	    String[] comboItmes = { "Klein...............................................600x600", "Mittel..............................................750x750", "Riesig.............................................900x900"};
	    final JComboBox combos = new JComboBox(comboItmes);
	    combos.setBounds(75, 70, 250, 25);
	    
	    final JButton okay = new JButton(new ImageIcon(getClass().getResource(Einstellungen.getMenuImageFolderPath()+"okay.png")));
	    okay.setBounds(35,105,150,50);
	    okay.setMargin(new Insets(0,0,0,0));			
	    okay.setBorder(BorderFactory.createEmptyBorder());
	    okay.setContentAreaFilled(false);
	    okay.addMouseListener(new MouseListener(){
			public void mouseClicked(MouseEvent e) {
				buttonSound.play();
				int k = 0; 
		    	if (combos.getSelectedIndex() == 0){
		    		k = 1;
		    	}else if (combos.getSelectedIndex() == 1) {
					k = 2;
				}else if (combos.getSelectedIndex() == 2) {
					k = 3;
				}  	
		    	try {
					new Mapeditor(true, k);
					questionWeg();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
			public void mouseEntered(MouseEvent e) {
//				okay.setBounds(15,105,150,50);
			}
			public void mouseExited(MouseEvent e) {
//				okay.setBounds(35,105,150,50);
			}
			public void mousePressed(MouseEvent e) {
			}
			public void mouseReleased(MouseEvent e) {
			}});
	    
	    final JButton abbrechen = new JButton(new ImageIcon(getClass().getResource(Einstellungen.getMenuImageFolderPath()+"abbrechen.png")));
	    abbrechen.setBounds(200,105,150,50);
	    abbrechen.setMargin(new Insets(0,0,0,0));			
	    abbrechen.setBorder(BorderFactory.createEmptyBorder());
	    abbrechen.setContentAreaFilled(false);
	    abbrechen.addMouseListener(new MouseListener(){
			public void mouseClicked(MouseEvent e) {
				buttonSound.play();
				questionWeg();
			}
			public void mouseEntered(MouseEvent e) {
//				abbrechen.setBounds(180,105,150,50);
			}
			public void mouseExited(MouseEvent e) {
//				abbrechen.setBounds(200,105,150,50);
			}
			public void mousePressed(MouseEvent e) {
			}
			public void mouseReleased(MouseEvent e) {
			}});
	    
	    this.add(okay);
	    this.add(abbrechen);    	
	    this.add(combos);
	    this.add(frage);
        pack();
    }

    /**
     * Disposes the frame.
     */
    public void questionWeg(){
    	this.dispose();
    }
}
